home *** CD-ROM | disk | FTP | other *** search
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Newsgroups: comp.lang.c
- Subject: Re: Incrementing enumerat
- Date: 4 Feb 1996 00:34:36 GMT
- Organization: Ripco Communications, Inc.
- Message-ID: <4f0uus$al9@gail.ripco.com>
- NNTP-Posting-Host: foley.ripco.com
-
- Kimberley Burchett <burchett>
- in <4erc78$g0b@mastermind.odi.com> wrote:
-
- >Andy.Law@bbsrc.ac.uk (Andy Law) wrote:
- >>for (EnumeratedType eIndex = enum_first; eIndex < enum_last; eIndex++) {
- >>
- >> /* do something */
- >>}
-
- > Enums are constants and have no math semantics. But you can convert
- >enums to ints (although not vice versa). Try replacing EnumeratedType
- >with int -- you can increment the int and compare it to enum_first and
- >enum_last. However, you won't be able to pass eIndex to any function
- >expecting EnumeratedType w/o explicitly casting it.
-
- Since Mr. Law and Ms. Burchett have both posted to comp.lang.c, this
- response concerns C. If they have a non-C (C++) problem, then they
- should not post to comp.lang.c.
-
- I suggest you reread your C language reference. A member of an
- enumeration is a constant. If the C++-ism of Mr. Law's example is
- corrected:
- EnumeratedType eIndex;
- for (eIndex = enum_first; eIndex < enum_last; eIndex++) {
- /* do something */
- }
- there is no problem. eIndex is not a member of an enumeration but a
- variable of type EnumeratedType. The constants of the enumeration are
- integral constant values, a variable of type EnumeratedType is an
- integral variable. "Each enumerated type shall be compatible with an
- integer type" (6.5.2.2)
-
- > I have never had a problem with the semantics of enums, and have
-
- Yes, you have.
-
- >even found it useful that you can't convert int->enum. If you're
- >running into problems, you might consider using a different idiom.
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-